package com.smarttourism.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ShxUtils {
    public static Date extractBirthdayFromIdCard(String idCardNumber) throws ParseException {
        if (idCardNumber.length() == 18) {
            String birthDateStr = idCardNumber.substring(6, 14);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            return sdf.parse(birthDateStr);
        } else return null;
    }

    public static String convertIntArrayToString(Integer[] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            sb.append(array[i]);
            if (i < array.length - 1) {
                sb.append(";");
            }
        }
        return sb.toString();
    }

    public static int[] convertStringToIntArray(String str) {
        if (str == null || str.isEmpty()) {
            return new int[0];
        }
        String[] parts = str.split(";");
        int[] result = new int[parts.length];
        for (int i = 0; i < parts.length; i++) {
            try {
                result[i] = Integer.parseInt(parts[i]);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                // 如果某个部分无法转换为整数，可以选择返回错误值或者进行其他处理
                result[i] = 0;
            }
        }
        return result;
    }
}
